package puyu.manage.service.source.service;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import puyu.manage.service.source.dao.SysTSourceListMapper;
import puyu.manage.service.source.entity.SysTSourceList;
import puyu.manage.service.source.service.SysTSourceListService;
import org.springframework.stereotype.Service;
import puyu.manage.service.utils.IdUtils;
import puyu.manage.service.utils.StringUtils;
import puyu.manage.service.utils.except.CustomException;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * 字典子表(SysTSourceList)表服务实现类
 *
 * @author makejava
 * @since 2024-08-01 16:41:23
 */
@Service
public class SysTSourceListServiceImpl extends ServiceImpl<SysTSourceListMapper, SysTSourceList> implements SysTSourceListService {

    @Resource
    private SysTSourceListMapper sysTSourceListMapper;


    /**
     * 新增
     **/
    @Override
    public void insertSourceList(Map<String, Object> source) {

        String sourceCode = (String) source.get("sourceCode");

        if (StringUtils.isEmpty(sourceCode)){
            throw new CustomException("主表编码为空！");
        }

        source.put("id", IdUtils.simpleUUID());
        source.put("parentId", "0");

        sysTSourceListMapper.insertSourceList(source);

    }

    /**
     * 修改
     **/
    @Override
    public void updateSourceList(Map<String, Object> source) {

        String sourceCode = (String) source.get("sourceCode");

        if (StringUtils.isEmpty(sourceCode)){
            throw new CustomException("主表编码为空！");
        }

        sysTSourceListMapper.updateSourceList(source);

    }

    /**
     * 批量删除
     **/
    @Override
    public void deleteByListId(List<String> ids) {
        if (ObjectUtil.isNotEmpty(ids)){
            this.removeByIds(ids);
        }
    }

}

